package com.capgemini.cn.authority.data.entity;

import com.capgemini.cn.authority.data.core.BaseEntity;
import com.capgemini.cn.authority.data.enums.AuthorityType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.List;

/**
 * <p>权限类型表</p>
 * Created at 2017/8/23
 *
 * @author Andriy
 */
@Entity
@Table(name = "cg_authorities_type")
@NoArgsConstructor
@AllArgsConstructor
public class AuthoritiesType extends BaseEntity {

    /**
     * 类型名称
     */
    @Column(name = "type_name", length = 50, nullable = false)
    @Getter
    private String typeName;

    /**
     * 权限类型中对应的具体权限数据
     */
    @OneToMany(targetEntity = Authorities.class)
    @JoinColumn(name = "type_id")
    @Getter
    @Setter
    private List<Authorities> authorities;


    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public void setTypeName(AuthorityType type) {
        this.typeName = type.name();
    }
}
